<?php

class Silk_Zgb_Block_Renderer_ItemsTotalAll extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    /**
     * @param Varien_Object $row
     * @return mixed
     */
    public function render(Varien_Object $row)
    {
        $shipping_id = $row->getId();
        /** @var Silk_Tms_Model_Mysql4_Shipping_Order_Collection $collection */
        $collection = Mage::getModel('tms/shipping_order')->getCollection();
        $orders = $collection->addFieldToFilter('shipping_id', $shipping_id);

        $itemsTotal = 0;
        /** @var Silk_Tms_Model_Shipping_Order $order */
        foreach ($orders as $order) {
            $orderId = $order->getOrderId();
            /** @var Mage_Sales_Model_Order $mageOrder */
            $mageOrder = Mage::getModel('sales/order')->load($orderId);
            $itemsTotal += $mageOrder->getTotalQtyOrdered();
        }

        return $itemsTotal ?: '0';
    }
}